package org.red_cross_service.controller;

import org.red_cross_service.common.anno.NoNeedToken;
import org.red_cross_service.common.response.Response;
import org.red_cross_service.domain.entity.SysUserEntity;
import org.red_cross_service.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/api/sysUser")
@CrossOrigin
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    //修改密码
    @NoNeedToken
    @RequestMapping("/updatePassword")
    public Response updatePassword(@RequestBody SysUserEntity sysUserEntity){
        if(sysUserService.updatePassword(sysUserEntity)==0){
            return Response.error("密码错误");
        }
        return Response.success("修改成功");
    }

    //后台用户登录接口
    @NoNeedToken
    @RequestMapping("/login")
    public Response login(String username, String password) {
        return sysUserService.login(username, password);
    }

    @NoNeedToken
    //后台新增用户接口
    @RequestMapping("/add")
    public Response add(@RequestBody SysUserEntity sysUserEntity) {
        return sysUserService.add(sysUserEntity);
    }
    //后台修改用户接口
    @NoNeedToken
    @RequestMapping("/update")
    public Response update(@RequestBody SysUserEntity sysUserEntity) {
        return sysUserService.update(sysUserEntity);
    }

    //后台删除用户接口
    @NoNeedToken
    @RequestMapping("/delete")
    public Response delete(@RequestBody SysUserEntity sysUserEntity) {
        return sysUserService.delete(sysUserEntity.getId());
    }

    //查询单个用户接口
    @NoNeedToken
    @RequestMapping("/selectOne")
    public Response selectOne(@RequestBody SysUserEntity sysUserEntity) {
        return sysUserService.selectOne(sysUserEntity);
    }

    //查询用户列表接口
    @NoNeedToken
    @RequestMapping("/list")
    public Response getSysUserList(@RequestBody SysUserEntity sysUserEntity) {
        return sysUserService.getSysUserList(sysUserEntity);
    }

}
